import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import elementui from 'element-ui'
import axios from 'axios'
import 'element-ui/lib/theme-chalk/index.css'
//导入echarts数据库可视化
import * as echarts from 'echarts';
//将echarts挂载至Vue属性中，属性名$echarts
Vue.prototype.$echarts = echarts;

//axios域名配置，即服务端API服务器域名，
axios.defaults.baseURL = 'http://127.0.0.1:5000'
//把axios挂载至Vue全局属性中
Vue.prototype.$http = axios



//vue中注册使用element-ui
Vue.use(elementui)

Vue.config.productionTip = false

//前置路由守卫，判断路由权限
router.beforeEach((to, from, next) => {
  const {
    role
  } = to.meta;
  if (role) {
    const admin = JSON.parse(localStorage.getItem('admin'))
    if (role != admin.role) {
      alert('您无权访问！');
    } else {
      next()
    }
  } else {
    next();
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')